﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Twi.COMMON.Core;
using Twi.Pages.SCS.BLL;

namespace Twi.Pages.SCS
{
    public class User
    {
        /// <summary>
        /// 获取所有用户
        /// </summary>
        /// <returns></returns>
        public TwiReturn GetAllList()
        {
            TwiReturn twi = new TwiReturn();
            twi.rightName = "pass";
            try
            {
                UserContext.CheckRight(ref twi);
                var list = _User.Instance.GetAllList();
                twi.totalCount = list.Count;
                twi.data = JSSerialize.Serialize(list);
                twi.success = true;
            }
            catch (System.Exception ex)
            {
                twi.errors = ex.Message;
            }
            return twi;
        }

        /// <summary>
        /// 获取所用用户 作为下拉选项格式JSON
        /// </summary>
        /// <returns></returns>
        public string GetUserOption()
        {
            var list = _User.Instance.GetAllList();
            string str = JSSerialize.Serialize(list);
            return str;
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        public TwiReturn LoginIn(string userName, string pwd)
        {
            TwiReturn twi = new TwiReturn();
            twi.rightName = "pass";
            try
            {
                var user = _User.Instance.LoginIn(userName,pwd);
                user.FPwd = "";
                UserContext.CurrentUser = user;
                twi.data = user;
                twi.success = true;
            }
            catch (System.Exception ex)
            {
                twi.errors = ex.Message;
            }
            return twi;
        }
        /// <summary>
        /// 注销
        /// </summary>
        /// <returns></returns>
        public TwiReturn LoginOut()
        {
            TwiReturn twi = new TwiReturn();
            twi.rightName = "pass";
            UserContext.CurrentUser = null;
            twi.success = true;
            return twi;
        }
    }
}
